/**
 * 
 */
package cn.tonyqiu.wonuly.web.impl;

import java.util.ArrayList;
import java.util.List;

import org.gwtwidgets.server.spring.GWTSpringController;

import cn.tonyqiu.wonuly.client.rpc.LookupService;
import cn.tonyqiu.wonuly.model.Account;
import cn.tonyqiu.wonuly.model.Category;
import cn.tonyqiu.wonuly.service.LookupManager;

/**
 * @author <a href="mailto:tony.qiu.smart@gmail.com">Tony Qiu</a>
 * 
 */
public class LookupServiceImpl extends GWTSpringController implements LookupService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5936055904907181133L;

	private LookupManager lookupManager;
	
	/**
	 * @return the lookupManager
	 */
	public LookupManager getLookupManager() {
		return lookupManager;
	}

	/**
	 * @param lookupManager the lookupManager to set
	 */
	public void setLookupManager(LookupManager lookupManager) {
		this.lookupManager = lookupManager;
	}

	/* (non-Javadoc)
	 * @see cn.tonyqiu.wonuly.client.rpc.LookupService#getAccountByUser()
	 */
	@Override
	public List<String> getAccountByUser() {
		List<String> returnList = new ArrayList<String>();
		List<Account> accountList= lookupManager.getAccountsByUser();
		for(Account a : accountList) {
			returnList.add(a.getName());
		}
		return returnList;
	}

	/* (non-Javadoc)
	 * @see cn.tonyqiu.wonuly.client.rpc.LookupService#getCategoryByUser()
	 */
	@Override
	public List<String> getCategoryByUser() {
		List<String> returnList = new ArrayList<String>();
		List<Category> categoryList = lookupManager.getCategoriesByUser();
		for(Category c: categoryList) {
			returnList.add(c.getName());
		}
		return returnList;
	}

}
